
!include "MUI2.nsh"

!define REG_KEY_UNINSTALL "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\GooOutSync"
!define REG_KEY_PREF_UNINSTALL "Software\JavaSoft\Prefs\com\vgold\goooutsync"
!define REG_KEY_SOFTWARE "SOFTWARE\GooOutSync"

RequestExecutionLevel admin

Name "Google Outlook Sync"
OutFile "dist\goooutsync-setup-beta-${VERSION}.exe"
InstallDir "$PROGRAMFILES\GooOutSync"

;Get install folder from registry for updates
InstallDirRegKey HKCU "${REG_KEY_SOFTWARE}" ""

SetCompressor /SOLID lzma
SetCompressorDictSize 32
 
!define MUI_ABORTWARNING
!define MUI_FINISHPAGE_RUN "$INSTDIR\GooOutSync.exe"
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\win.bmp"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

ShowUninstDetails show

Section "Program Files"
  SetOutPath "$INSTDIR"
  SetOverwrite on
; File /r /x ".svn" /x "*.jar" /x "third-party"
  File /r /x ".svn" "lib"
  File /r /x ".svn" "win32"
  File "GooOutSync.exe"
;  File "PMS.bat"
  File "goooutsync.jar"
  File "log4j.properties"
;  File "MediaInfo.dll"
;  File "MediaInfo64.dll"
;  File "CHANGELOG"
;  File "README"
;  File "FAQ"
;  File "LICENSE.txt"
  SetOverwrite off
;  File "WEB.conf"
;  File "logback.xml"
  
  ;Store install folder
  WriteRegStr HKCU "${REG_KEY_SOFTWARE}" "" $INSTDIR
 
 ;Create uninstaller
 WriteUninstaller "$INSTDIR\Uninst.exe"
 
  WriteRegStr HKEY_LOCAL_MACHINE "${REG_KEY_UNINSTALL}" "DisplayName" "Google Outlook Sync"
  WriteRegStr HKEY_LOCAL_MACHINE "${REG_KEY_UNINSTALL}" "UninstallString" '"$INSTDIR\uninst.exe"'
  WriteUnInstaller "uninst.exe"
SectionEnd
 
Section "Start Menu Shortcuts"
  SetShellVarContext all
  CreateDirectory "$SMPROGRAMS\GooOutSync"
  CreateShortCut "$SMPROGRAMS\GooOutSync\GooOutSync.lnk" "$INSTDIR\GooOutSync.exe" "" "$INSTDIR\GooOutSync.exe" 0
  CreateShortCut "$SMPROGRAMS\GooOutSync\Uninstall.lnk" "$INSTDIR\uninst.exe" "" "$INSTDIR\uninst.exe" 0
SectionEnd
 
Section "Desktop shortcut"
  SetShellVarContext all
  CreateShortCut "$DESKTOP\GooOutSync.lnk" "$INSTDIR\GooOutSync.exe"
SectionEnd

Section "Uninstall"
  SetShellVarContext all

  Delete /REBOOTOK "$INSTDIR\Uninst.exe"
;  RMDir /R /REBOOTOK "$INSTDIR\plugins"
;  RMDir /R /REBOOTOK "$INSTDIR\renderers"
  RMDir /R /REBOOTOK "$INSTDIR\win32"
  RMDir /R /REBOOTOK "$INSTDIR\lib"
  Delete /REBOOTOK "$INSTDIR\GooOutSync.exe"
;  Delete /REBOOTOK "$INSTDIR\PMS.bat"
  Delete /REBOOTOK "$INSTDIR\goooutsync.jar"
  Delete /REBOOTOK "$INSTDIR\goooutsync.log*"
;  Delete /REBOOTOK "$INSTDIR\MediaInfo.dll"
;  Delete /REBOOTOK "$INSTDIR\MediaInfo64.dll"
  Delete /REBOOTOK "$INSTDIR\CHANGELOG"
;  Delete /REBOOTOK "$INSTDIR\WEB.conf"
  Delete /REBOOTOK "$INSTDIR\README"
  Delete /REBOOTOK "$INSTDIR\log4j.properties"
  Delete /REBOOTOK "$INSTDIR\FAQ"
  Delete /REBOOTOK "$INSTDIR\LICENSE.txt"
  Delete /REBOOTOK "$INSTDIR\debug.log"
  Delete /REBOOTOK "$INSTDIR\logback.xml"
  RMDir /REBOOTOK "$INSTDIR"
  
 
  Delete /REBOOTOK "$DESKTOP\GooOutSync.lnk"
  RMDir /REBOOTOK "$SMPROGRAMS\GooOutSync"
  Delete /REBOOTOK "$SMPROGRAMS\GooOutSync\GooOutSync.lnk"
   Delete /REBOOTOK "$SMPROGRAMS\GooOutSync\Uninstall.lnk"
 MessageBox MB_YESNO "Would you like to keep all application settings?" IDYES true IDNO false
true:
  DetailPrint "Keeping all application settings..."
  Goto next
false:
	DetailPrint "Removing all application settings..."
  DeleteRegKey HKEY_CURRENT_USER "${REG_KEY_PREF_UNINSTALL}"
next:
  DeleteRegKey HKEY_LOCAL_MACHINE "${REG_KEY_UNINSTALL}"
  DeleteRegKey HKCU "${REG_KEY_SOFTWARE}"
SectionEnd
